<?php
/* SVN FILE: $Id: item_createforum.php 247 2009-10-22 15:31:39Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* Create a Forum item
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 247 $
* @lastrevision $Date: 2009-10-22 15:31:39 +0000 (Thu, 22 Oct 2009) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2009-10-22 15:31:39 +0000 (Thu, 22 Oct 2009) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/items/forum/item_createforum.php $
*/

class item_createforum extends templateItem
{
	/**
	 * The default name of the item
	 *
	 * @access	protected
	 * @var		string
	 */
	protected $defaultName = "Create a Forum";
	
	/**
	 * The default description of the item
	 *
	 * @access	protected
	 * @var		string
	 */
	protected $defaultDescription = "Create a forum for yourself.";
	
	// Inherited Properties
	/**
	 * Item setting to allow multiple instances within ibMarket 
	 *
	 * @access	protected
	 * @var		boolean
	 */
	protected $allowMultiple = true;
	
	/**
	 * Item specific setting
	 *
	 * @access	protected
	 * @var		array
	 */
	protected $itemSettings = array();
	
	/**
	 * Forums that was created with this item
	 *
	 * @access	protected
	 * @var		array
	 */
	protected $forums = array();
	
	/**
	 * Constructor to setup the item
	 *
	 * @access	public
	 * @param	ipsRegistry	$registry	IPB registry
	 * @param	array		&$item		The item information
	 */
	public function __construct(ipsRegistry $registry, array &$item)
	{
		parent::__construct($registry, $item);
		
		if($item['item_config'] || $item['item_id'] != 0)
		{
			$this->itemSettings = unserialize($item['item_config']);
		}
		else
		{
			$this->itemSettings['lasting'] = 21;
			$this->itemSettings['time_unit'] = 86400;
			$this->itemSettings['parent_forum'] = 0;
			$this->itemSettings['set_password'] = 1;
			$this->itemSettings['allow_html'] = 0;
			$this->itemSettings['allow_bbcode'] = 1;
			$this->itemSettings['allow_quick_reply'] = 1;
			$this->itemSettings['allow_polls'] = 1;
			$this->itemSettings['allow_poll_bump'] = 0;
			$this->itemSettings['allow_rating'] = 0;
			$this->itemSettings['allow_post_inc'] = 1;
			$this->itemSettings['min_posts_post'] = 0;
			$this->itemSettings['min_posts_view'] = 0;
			$this->itemSettings['can_view_others'] = 1;
			$this->itemSettings['prune'] = 100;
			$this->itemSettings['sort_key'] = 'last_post';
			$this->itemSettings['sort_order'] = 'Z-A';
			$this->itemSettings['sort_filter'] = 'all';
			$this->itemSettings['market_reply'] = 0;
			$this->itemSettings['market_reply_amount'] = 0;
			$this->itemSettings['market_topic'] = 0;
			$this->itemSettings['market_topic_amount'] = 0;
			$this->itemSettings['edit_post'] = 1;
			$this->itemSettings['edit_title'] = 1;
			$this->itemSettings['delete_post'] = 0;
			$this->itemSettings['delete_topic'] = 0;
			$this->itemSettings['open_topic'] = 1;
			$this->itemSettings['close_topic'] = 1;
			$this->itemSettings['pin_topic'] = 1;
			$this->itemSettings['unpin_topic'] = 1;
			$this->itemSettings['split_merge'] = 0;
			$this->itemSettings['mod_can_set_open_time'] = 1;
			$this->itemSettings['mod_can_set_close_time'] = 1;
			$this->itemSettings['show_forum'] = array('*');
			$this->itemSettings['read_topic'] = array('*');
			$this->itemSettings['reply_topic'] = array('*');
			$this->itemSettings['start_topic'] = array('*');
			$this->itemSettings['upload'] = array('*');
			$this->itemSettings['download'] = array('*');
			$this->itemSettings['move_deleted'] = 0;
		}
		
		// Remove any old forums
		$this->forums = $item['settings'] ? unserialize($item['settings']) : array();
		if(count($this->forums) && $this->request['request_method'] != 'post' && IN_ACP == 0)
		{
			foreach($this->forums as $f_id => $end)
			{
				if($end < IPS_UNIX_TIME_NOW)
				{
					if($this->itemSettings['move_deleted'])
					{
						$this->DB->update( 'topics', array( 'forum_id' => $this->itemSettings['move_deleted'] ), 'forum_id='.$f_id );
						$this->DB->update( 'polls' , array( 'forum_id' => $this->itemSettings['move_deleted'] ), 'forum_id='.$f_id );
						$this->DB->update( 'voters', array( 'forum_id' => $this->itemSettings['move_deleted'] ), 'forum_id='.$f_id );
					}
					else
					{
						$this->DB->delete( 'topics', 'forum_id='.$f_id );
						$this->DB->delete( 'polls' , 'forum_id='.$f_id );
						$this->DB->delete( 'voters', 'forum_id='.$f_id );
					}
					$this->DB->delete( 'forums', 'id='.$f_id );
					$this->DB->delete( 'moderators', 'forum_id='.$f_id );
					$this->DB->delete( 'forum_tracker', 'forum_id='.$f_id );
					$this->DB->update( 'forums', array( 'parent_id' => $this->item_config['move_deleted'] ? $this->item_config['move_deleted'] : $this->item_config['parent_forum']), "parent_id=".$f_id ); // So there is not any lost forums
					
					unset($this->forums[$f_id]);
					$this->DB->update('market_items',array('settings'=>serialize($this->forums)),"item_id=".$this->item['item_id']);
					ipsRegistry::cache()->rebuildCache('market_items','ibmarket');
					$this->registry->getClass('output')->silentRedirect( $this->settings['base_url'] . $_SERVER['QUERY_STRING'] );
				}
			}
		}
	}
	
	/**
	 * Additional settings when adding/editing the item
	 *
	 * @access	public
	 * @return	string|bool	string if there is something to edit, false otherwise
	 */
	public function adminForm()
	{
		$this->lang->loadLanguageFile( array( 'admin_forums' ), 'forums' );
		$this->lang->loadLanguageFile( array( 'admin_manage' ), 'ibmarket' );
		
		require_once( IPSLib::getAppDir( 'forums' ) . "/sources/classes/forums/class_forums.php" );
		require_once( IPSLib::getAppDir( 'forums' ) . '/sources/classes/forums/admin_forum_functions.php' );
		
		$forum_functions = new admin_forum_functions( $this->registry );
		$forum_functions->forumsInit();
		$forumlist = $forum_functions->adForumsForumList();
		$deleteForum = array_merge(array(array(0, $this->lang->words['remove_all_posts'])), $forumlist);
		
		$perm_masks   = array();
		$perm_masks[] = array('*',$this->lang->words['frm_global']);
		$this->DB->build( array( 'select' => '*', 'from' => 'forum_perms' ) );
		$q = $this->DB->execute();
		while ( $r = $this->DB->fetch($q) )
		{
			$perm_masks[] = array( $r['perm_id'], $r['perm_name'] );
		}
		
		$dd_prune    = array( 
							 0 => array( 1, $this->lang->words['for_today'] ),
							 1 => array( 5, $this->lang->words['for_last5']  ),
							 2 => array( 7, $this->lang->words['for_last7']  ),
							 3 => array( 10, $this->lang->words['for_last10'] ),
							 4 => array( 15, $this->lang->words['for_last15'] ),
							 5 => array( 20, $this->lang->words['for_last20'] ),
							 6 => array( 25, $this->lang->words['for_last25'] ),
							 7 => array( 30, $this->lang->words['for_last30'] ),
							 8 => array( 60, $this->lang->words['for_last60'] ),
							 9 => array( 90, $this->lang->words['for_last90'] ),
							 10=> array( 100, $this->lang->words['for_showall']     ),
							);
		
		$dd_order    = array( 
							 0 => array( 'last_post', $this->lang->words['for_s_last'] ),
							 1 => array( 'title'    , $this->lang->words['for_s_topic'] ),
							 2 => array( 'starter_name', $this->lang->words['for_s_name'] ),
							 3 => array( 'posts'    , $this->lang->words['for_s_post'] ),
							 4 => array( 'views'    , $this->lang->words['for_s_view'] ),
							 5 => array( 'start_date', $this->lang->words['for_s_date'] ),
							 6 => array( 'last_poster_name'   , $this->lang->words['for_s_poster'] )
							);
		
		$dd_by       = array( 
							 0 => array( 'Z-A', $this->lang->words['for_desc'] ),
							 1 => array( 'A-Z', $this->lang->words['for_asc']  )
							);
							
		$dd_filter	 = array(
							 0 => array( 'all', 	$this->lang->words['for_all'] ),
							 1 => array( 'open', 	$this->lang->words['for_open'] ),
							 2 => array( 'hot',		$this->lang->words['for_hot'] ),
							 3 => array( 'poll',	$this->lang->words['for_poll'] ),
							 4 => array( 'locked',	$this->lang->words['for_locked'] ),
							 5 => array( 'moved',	$this->lang->words['for_moved'] ),
							 6 => array( 'istarted', $this->lang->words['for_istarted'] ),
							 7 => array( 'ireplied', $this->lang->words['for_ireplied'] ),
							);
		
		$timeUnits = array(array(86400,$this->lang->words['days']),array(604800,$this->lang->words['weeks']));
		
		$form['lasting'] = ipsRegistry::getClass('output')->formSimpleInput('item[lasting]', $this->itemSettings['lasting']);
		$form['time_unit'] = ipsRegistry::getClass('output')->formDropdown('item[time_unit]', $timeUnits, $this->itemSettings['time_unit']);
		$form['parent_forum'] = ipsRegistry::getClass('output')->formDropdown('item[parent_forum]', $forumlist, $this->itemSettings['parent_forum']);
		$form['set_password'] = ipsRegistry::getClass('output')->formYesNo('item[set_password]', $this->itemSettings['set_password']);
		$form['allow_html'] = ipsRegistry::getClass('output')->formYesNo('item[allow_html]', $this->itemSettings['allow_html']);
		$form['allow_bbcode'] = ipsRegistry::getClass('output')->formYesNo('item[allow_bbcode]', $this->itemSettings['allow_bbcode']);
		$form['allow_quick_reply'] = ipsRegistry::getClass('output')->formYesNo('item[allow_quick_reply]', $this->itemSettings['allow_quick_reply']);
		$form['allow_polls'] = ipsRegistry::getClass('output')->formYesNo('item[allow_polls]', $this->itemSettings['allow_polls']);
		$form['allow_poll_bump'] = ipsRegistry::getClass('output')->formYesNo('item[allow_poll_bump]', $this->itemSettings['allow_poll_bump']);
		$form['allow_rating'] = ipsRegistry::getClass('output')->formYesNo('item[allow_rating]', $this->itemSettings['allow_rating']);
		$form['allow_post_inc'] = ipsRegistry::getClass('output')->formYesNo('item[allow_post_inc]', $this->itemSettings['allow_post_inc']);
		$form['min_posts_post'] = ipsRegistry::getClass('output')->formInput('item[min_posts_post]', $this->itemSettings['min_posts_post']);
		$form['min_posts_view'] = ipsRegistry::getClass('output')->formInput('item[min_posts_view]', $this->itemSettings['min_posts_view']);
		$form['can_view_others'] = ipsRegistry::getClass('output')->formYesNo('item[can_view_others]', $this->itemSettings['can_view_others']);
		$form['prune'] = ipsRegistry::getClass('output')->formDropdown('item[prune]', $dd_prune, $this->itemSettings['prune']);
		$form['sort_key'] = ipsRegistry::getClass('output')->formDropdown('item[sort_key]', $dd_order, $this->itemSettings['sort_key']);
		$form['sort_order'] = ipsRegistry::getClass('output')->formDropdown('item[sort_order]', $dd_by, $this->itemSettings['sort_order']);
		$form['sort_filter'] = ipsRegistry::getClass('output')->formDropdown('item[sort_filter]', $dd_filter, $this->itemSettings['sort_filter']);
		$form['market_reply'] = ipsRegistry::getClass('output')->formYesNo('item[market_reply]', $this->itemSettings['market_reply']);
		$form['market_topic'] = ipsRegistry::getClass('output')->formYesNo('item[market_topic]', $this->itemSettings['market_topic']);
		$form['market_reply_amount'] = marketFormatter::currencyFormat(ipsRegistry::getClass('output')->formSimpleInput('item[market_reply_amount]', $this->itemSettings['market_reply_amount'], 10));
		$form['market_topic_amount'] = marketFormatter::currencyFormat(ipsRegistry::getClass('output')->formSimpleInput('item[market_topic_amount]', $this->itemSettings['market_topic_amount'], 10));
		$form['edit_post'] = ipsRegistry::getClass('output')->formYesNo('item[edit_post]', $this->itemSettings['edit_post']);
		$form['edit_title'] = ipsRegistry::getClass('output')->formYesNo('item[edit_title]', $this->itemSettings['edit_title']);
		$form['delete_post'] = ipsRegistry::getClass('output')->formYesNo('item[delete_post]', $this->itemSettings['delete_post']);
		$form['delete_topic'] = ipsRegistry::getClass('output')->formYesNo('item[delete_topic]', $this->itemSettings['delete_topic']);
		$form['open_topic'] = ipsRegistry::getClass('output')->formYesNo('item[open_topic]', $this->itemSettings['open_topic']);
		$form['close_topic'] = ipsRegistry::getClass('output')->formYesNo('item[close_topic]', $this->itemSettings['close_topic']);
		$form['pin_topic'] = ipsRegistry::getClass('output')->formYesNo('item[pin_topic]', $this->itemSettings['pin_topic']);
		$form['unpin_topic'] = ipsRegistry::getClass('output')->formYesNo('item[unpin_topic]', $this->itemSettings['unpin_topic']);
		$form['split_merge'] = ipsRegistry::getClass('output')->formYesNo('item[split_merge]', $this->itemSettings['split_merge']);
		$form['mod_can_set_open_time'] = ipsRegistry::getClass('output')->formYesNo('item[mod_can_set_open_time]', $this->itemSettings['mod_can_set_open_time']);
		$form['mod_can_set_close_time'] = ipsRegistry::getClass('output')->formYesNo('item[mod_can_set_close_time]', $this->itemSettings['mod_can_set_close_time']);
		$form['show_forum'] = ipsRegistry::getClass('output')->formMultiDropdown('item[show_forum][]', $perm_masks, $this->itemSettings['show_forum']);
		$form['read_topic'] = ipsRegistry::getClass('output')->formMultiDropdown('item[read_topic][]', $perm_masks, $this->itemSettings['read_topic']);
		$form['reply_topic'] = ipsRegistry::getClass('output')->formMultiDropdown('item[reply_topic][]', $perm_masks, $this->itemSettings['reply_topic']);
		$form['start_topic'] = ipsRegistry::getClass('output')->formMultiDropdown('item[start_topic][]', $perm_masks, $this->itemSettings['start_topic']);
		$form['upload'] = ipsRegistry::getClass('output')->formMultiDropdown('item[upload][]', $perm_masks, $this->itemSettings['upload']);
		$form['download'] = ipsRegistry::getClass('output')->formMultiDropdown('item[download][]', $perm_masks, $this->itemSettings['download']);
		$form['move_deleted'] = ipsRegistry::getClass('output')->formDropdown('item[move_deleted]', $deleteForum, $this->itemSettings['move_deleted']);
		return <<<EOF
				<li>
					<label>
						{$this->lang->words['how_long_create_forum']}
						<span class="desctext">{$this->lang->words['how_long_create_forum_desc']}</span>
					</label>
					<div style='display: inline-block'>
						{$form['lasting']}
						{$form['time_unit']}
					</div>
				</li>
				<li>
					<label>{$this->lang->words['create_forum_parent']}</label>
					{$form['parent_forum']}
				</li>
				<li>
					<label>{$this->lang->words['create_forum_password']}</label>
					{$form['most_items']}
				</li>
				<li>
					<label>
						{$this->lang->words['frm_f_post_html']}
						<span class="desctext">{$this->lang->words['frm_f_post_html_info']}</span>
					</label>
					{$form['allow_html']}
				</li>
				<li>
					<label>{$this->lang->words['frm_f_post_bb']}</label>
					{$form['allow_bbcode']}
				</li>
				<li>
					<label>{$this->lang->words['frm_f_post_qreply']}</label>
					{$form['allow_quick_reply']}
				</li>
				<li>
					<label>{$this->lang->words['frm_f_post_poll']}</label>
					{$form['allow_polls']}
				</li>
				<li>
					<label>
						{$this->lang->words['frm_f_post_bump']}
						<span class="desctext">{$this->lang->words['frm_f_post_bump_info']}</span>
					</label>
					{$form['allow_poll_bump']}
				</li>
				<li>
					<label>{$this->lang->words['frm_f_post_rate']}</label>
					{$form['allow_rating']}
				</li>
				<li>
					<label>
						{$this->lang->words['frm_f_post_inc']}
						<span class="desctext">{$this->lang->words['frm_f_post_inc_info']}</span>
					</label>
					{$form['allow_post_inc']}
				</li>
				<li>
					<label>
						{$this->lang->words['frm_f_min_posts_post']}
						<span class="desctext">{$this->lang->words['frm_f_min_posts_post_info']}</span>
					</label>
					{$form['min_posts_post']}
				</li>
				<li>
					<label>
						{$this->lang->words['frm_f_min_posts_view']}
						<span class="desctext">{$this->lang->words['frm_f_min_posts_view_info']}</span>
					</label>
					{$form['min_posts_view']}
				</li>
				<li>
					<label>{$this->lang->words['frm_canviewothers']}</label>
					{$form['can_view_others']}
				</li>
				<li>
					<label>{$this->lang->words['frm_f_sort_cutoff']}</label>
					{$form['prune']}
				</li>
				<li>
					<label>{$this->lang->words['frm_f_sort_key']}</label>
					{$form['sort_key']}
				</li>
				<li>
					<label>{$this->lang->words['frm_f_sort_order']}</label>
					{$form['sort_order']}
				</li>
				<li>
					<label>{$this->lang->words['frm_f_sort_filter']}</label>
					{$form['sort_filter']}
				</li>
				<li>
					<label>{$this->lang->words['forum_reply_overwrite']}</label>
					{$form['market_reply']}
				</li>
				<li>
					<label>{$this->lang->words['forum_reply_amount']}</label>
					{$form['market_reply_amount']}
				</li>
				<li>
					<label>{$this->lang->words['forum_topic_overwrite']}</label>
					{$form['market_topic']}
				</li>
				<li>
					<label>{$this->lang->words['forum_topic_amount']}</label>
					{$form['market_topic_amount']}
				</li>
				<li>
					<label>{$this->lang->words['frm_m_edit']}</label>
					{$form['edit_post']}
				</li>
				<li>
					<label>{$this->lang->words['frm_m_topic']}</label>
					{$form['edit_title']}
				</li>
				<li>
					<label>{$this->lang->words['frm_m_delete']}</label>
					{$form['delete_post']}
				</li>
				<li>
					<label>{$this->lang->words['frm_m_deletetop']}</label>
					{$form['delete_topic']}
				</li>
				<li>
					<label>{$this->lang->words['frm_m_open']}</label>
					{$form['open_topic']}
				</li>
				<li>
					<label>{$this->lang->words['frm_m_close']}</label>
					{$form['close_topic']}
				</li>
				<li>
					<label>{$this->lang->words['frm_m_pin']}</label>
					{$form['pin_topic']}
				</li>
				<li>
					<label>{$this->lang->words['frm_m_unpin']}</label>
					{$form['unpin_topic']}
				</li>
				<li>
					<label>{$this->lang->words['frm_m_split']}</label>
					{$form['split_merge']}
				</li>
				<li>
					<label>{$this->lang->words['frm_m_opentime']}</label>
					{$form['mod_can_set_open_time']}
				</li>
				<li>
					<label>{$this->lang->words['frm_m_closetime']}</label>
					{$form['mod_can_set_close_time']}
				</li>
				<li>
					<label>{$this->lang->words['perm_forums_view']}</label>
					{$form['show_forum']}
				</li>
				<li>
					<label>{$this->lang->words['perm_forums_read']}</label>
					{$form['read_topic']}
				</li>
				<li>
					<label>{$this->lang->words['perm_forums_reply']}</label>
					{$form['reply_topic']}
				</li>
				<li>
					<label>{$this->lang->words['perm_forums_start']}</label>
					{$form['start_topic']}
				</li>
				<li>
					<label>{$this->lang->words['perm_forums_upload']}</label>
					{$form['upload']}
				</li>
				<li>
					<label>{$this->lang->words['perm_forums_download']}</label>
					{$form['download']}
				</li>
				<li>
					<label>{$this->lang->words['create_forum_move_deleted']}</label>
					{$form['move_deleted']}
				</li>

EOF;
	}
	
	/**
	 * Saving to adding/editing the item
	 *
	 * @access	public
	 * @param	array	&$item_info		The new item information to be stored in the database.
	 * @param	array	[$input]		Relavent input relating to the item
	 * @return	void
	 */
	public function adminSave(array &$item_info, array $input)
	{
		$setting = array();
		$setting['lasting'] = intval($input['lasting']);
		$setting['time_unit'] = intval($input['time_unit']);
		$setting['parent_forum'] = intval($input['parent_forum']);
		$setting['set_password'] = intval($input['set_password']) & 1;
		$setting['allow_html'] = intval($input['allow_html']) & 1;
		$setting['allow_bbcode'] = intval($input['allow_bbcode']) & 1;
		$setting['allow_quick_reply'] = intval($input['allow_quick_reply']) & 1;
		$setting['allow_polls'] = intval($input['allow_polls']) & 1;
		$setting['allow_poll_bump'] = intval($input['allow_poll_bump']) & 1;
		$setting['allow_rating'] = intval($input['allow_rating']) & 1;
		$setting['allow_post_inc'] = intval($input['allow_post_inc']) & 1;
		$setting['min_posts_post'] = intval($input['min_posts_post']);
		$setting['min_posts_view'] = intval($input['min_posts_view']);
		$setting['can_view_others'] = intval($input['can_view_others']) & 1;
		$setting['prune'] = intval($input['prune']);
		$setting['sort_key'] = $input['sort_key'];
		$setting['sort_order'] = $input['sort_order'];
		$setting['sort_filter'] = $input['sort_filter'];
		$setting['market_reply'] = intval($input['market_reply']) & 1;
		$setting['market_reply_amount'] = numbers::parseInt($input['market_reply_amount']);
		$setting['market_topic'] = intval($input['market_topic']) & 1;
		$setting['market_topic_amount'] = numbers::parseInt($input['market_topic_amount']);
		$setting['edit_post'] = intval($input['edit_post']) & 1;
		$setting['edit_title'] = intval($input['edit_title']) & 1;
		$setting['delete_post'] = intval($input['delete_post']) & 1;
		$setting['delete_topic'] = intval($input['delete_topic']) & 1;
		$setting['open_topic'] = intval($input['open_topic']) & 1;
		$setting['close_topic'] = intval($input['close_topic']) & 1;
		$setting['pin_topic'] = intval($input['pin_topic']) & 1;
		$setting['unpin_topic'] = intval($input['unpin_topic']) & 1;
		$setting['split_merge'] = intval($input['split_merge']) & 1;
		$setting['mod_can_set_open_time'] = intval($input['mod_can_set_open_time']) & 1;
		$setting['mod_can_set_close_time'] = intval($input['mod_can_set_close_time']) & 1;
		$setting['show_forum'] = is_array($input['show_forum']) ? (in_array('*', $input['show_forum']) ? array('*') : $input['show_forum'])  : array();
		$setting['read_topic'] = is_array($input['read_topic']) ? (in_array('*', $input['read_topic']) ? array('*') : $input['read_topic'])  : array();
		$setting['reply_topic'] = is_array($input['reply_topic']) ? (in_array('*', $input['reply_topic']) ? array('*') : $input['reply_topic'])  : array();
		$setting['start_topic'] = is_array($input['start_topic']) ? (in_array('*', $input['start_topic']) ? array('*') : $input['start_topic'])  : array();
		$setting['upload'] = is_array($input['upload']) ? (in_array('*', $input['upload']) ? array('*') : $input['upload'])  : array();
		$setting['download'] = is_array($input['download']) ? (in_array('*', $input['download']) ? array('*') : $input['download'])  : array();
		$setting['move_deleted'] = intval($input['move_deleted']);
		
		$item_info['item_config'] = serialize($setting);
	}
	
	/**
	 * When quick saving the price and stock
	 *
	 * @access	public
	 * @param	array	&$item_info		The new item information to be stored in the database.
	 * @param	string	$type			Possible values: 'stockprice', more possibly in the future
	 * @return	void
	 */
	public function adminQuickSave(array &$item_info, $type)
	{
		return;
	}
	
	/**
	 * When removing the item from ibMarket
	 *
	 * @access	public
	 * @return	void
	 */
	public function adminRemove()
	{
		return;
	}
	
	/**
	 * Viewing the file edits if any
	 *
	 * @access	public
	 * @return	string|bool	string if there is something to edit, false otherwise
	 */
	public function adminViewFileEdits()
	{
		return false;
	}
	
	/**
	 * Any admin AJAX functionality
	 *
	 * @access	public
	 * @param	array	$invItem		The inventory item
	 * @return	void
	 */
	public function adminAjax()
	{
		return;
	}
	
	/**
	 * Check and modify the intentory item information before storing in the database
	 *
	 * @access	public
	 * @param	array	&$invItem		The new inventory item information to be stored in the database.
	 * @return	bool	true if the item is successfully created, false otherwise
	 */
	public function publicOnCreateItem(array &$invItem)
	{
		return true;
	}
	
	/**
	 * When using the item
	 * Show a form and validate the form
	 *
	 * @access	public
	 * @param	array	$invItem		The inventory item
	 * @return	string|bool				string if there is a form to be used, true if successfully used, false otherwise
	 */
	public function publicUseItem(array &$invItem)
	{
		$this->registry->getClass('class_localization')->loadLanguageFile( array( 'public_items' ) );
		
		if($this->request['request_method'] == 'post')
		{
			require_once( IPS_ROOT_PATH . 'sources/classes/class_public_permissions.php' );
			$permissions = new classPublicPermissions( ipsRegistry::instance() );
			
			$description = IPSText::getTextClass('bbcode')->preDisplayParse(IPSText::getTextClass('bbcode')->preDbParse(IPSText::getTextClass('editor')->processRawPost('forum_description')));
			if(IPSText::getTextClass('bbcode')->error)
			{
				$this->registry->getClass('output')->showError(IPSText::getTextClass('bbcode')->error);
			}
			$this->request['forum_name'] = IPSText::getTextClass('bbcode')->xssHtmlClean( $this->request['forum_name'] );
			if(IPSText::getTextClass('bbcode')->error)
			{
				$this->registry->getClass('output')->showError(IPSText::getTextClass('bbcode')->error);
			}
			if(strlen($this->request['forum_name']) > 128 || !$this->request['forum_name'])
			{
				$this->registry->getClass('output')->showError('forum_name_error');
			}
			
			if(!$this->itemSettings['set_password'])
			{
				$this->request['forum_pass'] = '';
			}
			
			$forum = array(	'name'						=> $this->request['forum_name'],
							'name_seo'					=> IPSText::makeSeoTitle( $this->request['forum_name'] ),
							'description'				=> $description,
							'use_ibc'					=> $this->itemSettings['set_password'],
							'use_html'					=> $this->itemSettings['allow_html'],
							'status'					=> 1,
							'password'					=> $this->request['forum_pass'],
							'password_override'			=> '',
							'sort_key'					=> $this->itemSettings['sort_key'],
							'sort_order'				=> $this->itemSettings['sort_order'],
							'prune'						=> $this->itemSettings['prune'],
							'topicfilter'				=> $this->itemSettings['sort_filter'],
							'preview_posts'				=> 0,
							'allow_poll'				=> $this->itemSettings['allow_poll'],
							'allow_pollbump'			=> $this->itemSettings['allow_pollbump'],
							'forum_allow_rating'		=> $this->itemSettings['allow_rating'],
							'inc_postcount'				=> $this->itemSettings['allow_post_inc'],
							'parent_id'					=> $this->itemSettings['parent_forum'],
							'sub_can_post'				=> 1,
							'quick_reply'				=> $this->itemSettings['allow_quick_reply'],
							'redirect_on'				=> 0,
							'redirect_hits'				=> 0,
							'redirect_url'				=> '',
							'redirect_loc'				=> '',
							'notify_modq_emails'		=> '',
							'permission_showtopic'		=> 0,
							'min_posts_post'			=> $this->itemSettings['min_posts_post'],
							'min_posts_view'			=> $this->itemSettings['min_posts_view'],
							'can_view_others'			=> $this->itemSettings['can_view_others'],
							'hide_last_info'			=> 0,
							'permission_custom_error'	=> '',
							'market_reply'				=> $this->itemSettings['market_reply'],
							'market_reply_amount'		=> $this->itemSettings['market_reply_amount'],
							'market_topic'				=> $this->itemSettings['market_topic'],
							'market_topic_amount'		=> $this->itemSettings['market_topic_amount'],
						);
			
			$this->DB->insert( 'forums', $forum );
			$forum_id = $this->DB->getInsertId();
			
			$moderator = array( 
								'member_name'				=> $this->memberData['members_display_name'],
								'member_id'					=> $this->memberData['member_id'],
								'is_group'					=> 0,
								'edit_post'					=> $this->itemSettings['edit_post'],
								'edit_topic'				=> $this->itemSettings['edit_topic'],
								'delete_post'				=> $this->itemSettings['delete_post'],
								'delete_topic'				=> $this->itemSettings['delete_topic'],
								'view_ip'					=> 0,
								'open_topic'				=> $this->itemSettings['open_topic'],
								'close_topic'				=> $this->itemSettings['close_topic'],
								'mass_move'					=> 0,
								'mass_prune'				=> 0,
								'move_topic'				=> 0,
								'pin_topic'					=> $this->itemSettings['pin_topic'],
								'unpin_topic'				=> $this->itemSettings['unpin_topic'],
								'post_q'					=> 0,
								'topic_q'					=> 0,
								'allow_warn'				=> 0,
								'split_merge'				=> $this->itemSettings['split_merge'],
								'edit_user'					=> 0,
								'can_mm'					=> 0,
								'mod_can_set_open_time'		=> $this->itemSettings['mod_can_set_open_time'],
								'mod_can_set_close_time'	=> $this->itemSettings['mod_can_set_close_time'],
								'forum_id'					=> ',' . $forum_id . ',',
								'mod_bitoptions'			=> 0
							);
			
			$this->DB->insert('moderators', $moderator);
			
			$perms = array();
			foreach($this->itemSettings['show_forum'] as $id)
			{
				$perms['view'][$id] = 1;
			}
			foreach($this->itemSettings['read_topic'] as $id)
			{
				$perms['read'][$id] = 1;
			}
			foreach($this->itemSettings['reply_topic'] as $id)
			{
				$perms['reply'][$id] = 1;
			}
			foreach($this->itemSettings['start_topic'] as $id)
			{
				$perms['start'][$id] = 1;
			}
			foreach($this->itemSettings['upload'] as $id)
			{
				$perms['upload'][$id] = 1;
			}
			foreach($this->itemSettings['download'] as $id)
			{
				$perms['download'][$id] = 1;
			}
			
			$permissions->savePermMatrix( $perms, $forum_id, 'forum', 'forums' );
			
			if($this->itemSettings['lasting'])
			{
				$this->forums[$forum_id] = IPS_UNIX_TIME_NOW + $this->itemSettings['lasting'] * $this->itemSettings['time_unit'];
			}
			else
			{
				$this->forums[$forum_id] = 0;
			}
			$this->DB->update('market_items',array('settings'=>serialize($this->forums)),"item_id=".$this->item['item_id']);
			ipsRegistry::cache()->rebuildCache('market_items','ibmarket');
			ipsRegistry::cache()->rebuildCache('moderator','forums');
			
			$this->deleteItems($invItem);
			
			$this->writeLog($invItem, "Created forum ".$this->request['forum_name']);
			
			$this->registry->getClass('output')->redirectScreen( $this->lang->words['forum_created'], $this->settings['base_url'] . "showforum=".$forum_id );
		}
		
		$editor = IPSText::getTextClass('editor')->showEditor( '', 'forum_description' );
		
		$password = !$this->itemSettings['set_password'] ? "" : <<<EOF
				<li>
					<label><strong>{$this->lang->words['forum_password']}</strong><br />{$this->lang->words['blank_password']}</label>
					<input type='text' name='forum_pass' value='' size='32' class='input_text' />
				</li>

EOF;
		
		return <<<EOF
<form id='createForumForm' method="post" action="{$this->settings['base_url_with_app']}module=inventory&amp;section=item&amp;item={$invItem['i_id']}">
	<div id='createForum'class='block_wrap'>
		<h3 id='createForumHeader' class='maintitle'>{$this->item['item_name']}</h3>
		<fieldset class="row2">
			<ul>
				<li>
					<label><strong>{$this->lang->words['forum_name']}</strong></label>
					<input type='text' name='forum_name' value='' size='32' class='input_text' />
				</li>
				<li>
					<label><strong>{$this->lang->words['forum_description']}</strong></label>
					<br />
					{$editor}
				</li>
{$password}
			</ul>
		</fieldset>
		<fieldset class="submit">
			<input class="input_submit" type="submit" value="{$this->lang->words['create_forum_submit']}" name="submit" />
		</fieldset>
	</div>
</form>
EOF;
	}
	
	/**
	 * Any AJAX functionality
	 *
	 * @access	public
	 * @param	array	$invItem		The inventory item
	 * @return	void
	 */
	public function publicAjax(array &$invItem)
	{
		return;
	}
	
	/**
	 * When the item is being sold back
	 *
	 * @access	public
	 * @param	array	&$invItem	The inventory item information
	 * @return	bool				true if successful, false otherwise
	 */
	public function publicOnResoldItem(array &$invItem)
	{
		return true;
	}
	
	/**
	 * When the item is being restocked
	 *
	 * @access	public
	 * @param	array	&$item	The inventory item information
	 * @return	void
	 */
	public function onItemRestock(array &$item)
	{
		return;
	}
}
